package edu.lsnu.equipment_management_system.service.impl;

import edu.lsnu.equipment_management_system.mapper.select.paging.AdminReviewLogMapperWithPaging;
import edu.lsnu.equipment_management_system.pojo.domain.PageBean;
import edu.lsnu.equipment_management_system.pojo.domain.PageBeanDeal;
import edu.lsnu.equipment_management_system.pojo.vo.out.admin.AdminLogVo;
import edu.lsnu.equipment_management_system.pojo.vo.out.admin.AdminMsgInVo;
import edu.lsnu.equipment_management_system.pojo.vo.sql_conditions.PageBeginAndPageSizeVo;
import edu.lsnu.equipment_management_system.service.AdminReviewLogService;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author mzy
 * @Description 管理员审核之后的列表
 * @date 2018/11/25
 */
@Service
// 将page.size注入进来
@Data
@PropertySource({"classpath:resource.properties"})
@ConfigurationProperties(prefix = "page.admin.log")
public class AdminReviewLogServiceImpl implements AdminReviewLogService {
    private Integer size;
    @Autowired
    AdminReviewLogMapperWithPaging adminReviewLogMapperWithPaging;

    /**
     * @Description 购入审核日志
     * @author mzy
     * @time 2018-11-25
     * @see
     * @return   edu.lsnu.equipment_management_system.pojo.domain.PageBean<edu.lsnu.equipment_management_system.pojo.vo.out.admin.AdminLogVo>
     * @params  [currentPage]
     */
    @Override
    public PageBean<AdminLogVo> purchaseReviewLog(Integer currentPage) {
        // 获得总count：需要修改的位置
        Integer count = adminReviewLogMapperWithPaging.purchaseReviewLogCount();
        // 构造pageBean
        PageBean<AdminLogVo> pageBean = new PageBean<>();
        // 重复的代码
        PageBeginAndPageSizeVo pageBeginAndPageSizeVo = repeatCode(count, currentPage, pageBean);
        // 需要修改的位置
        List<AdminLogVo> adminLogVos =
                adminReviewLogMapperWithPaging.purchaseReviewLog(pageBeginAndPageSizeVo);

        pageBean.setContent(adminLogVos);

        return pageBean;
    }

    /**
     * @Description 报损报废审核日志
     * @author mzy
     * @time 2018-11-25
     * @see
     * @return   edu.lsnu.equipment_management_system.pojo.domain.PageBean<edu.lsnu.equipment_management_system.pojo.vo.out.admin.AdminLogVo>
     * @params  [currentPage]
     */
    @Override
    public PageBean<AdminLogVo> damageReviewLog(Integer currentPage) {
        // 获得总count：需要修改的位置
        Integer count = adminReviewLogMapperWithPaging.damageReviewLogCount();
        // 构造pageBean
        PageBean<AdminLogVo> pageBean = new PageBean<>();
        // 重复的代码
        PageBeginAndPageSizeVo pageBeginAndPageSizeVo = repeatCode(count, currentPage, pageBean);
        // 需要修改的位置
        List<AdminLogVo> adminLogVos =
                adminReviewLogMapperWithPaging.damageReviewLog(pageBeginAndPageSizeVo);

        pageBean.setContent(adminLogVos);

        return pageBean;
    }

    /**
     * @Description 维修维护审核日志
     * @author mzy
     * @time 2018-11-25
     * @see
     * @return   edu.lsnu.equipment_management_system.pojo.domain.PageBean<edu.lsnu.equipment_management_system.pojo.vo.out.admin.AdminLogVo>
     * @params  [currentPage]
     */
    @Override
    public PageBean<AdminLogVo> repairReviewLog(Integer currentPage) {
        // 获得总count：需要修改的位置
        Integer count = adminReviewLogMapperWithPaging.repairReviewLogCount();
        // 构造pageBean
        PageBean<AdminLogVo> pageBean = new PageBean<>();
        // 重复的代码
        PageBeginAndPageSizeVo pageBeginAndPageSizeVo = repeatCode(count, currentPage, pageBean);
        // 需要修改的位置
        List<AdminLogVo> adminLogVos =
                adminReviewLogMapperWithPaging.repairReviewLog(pageBeginAndPageSizeVo);

        pageBean.setContent(adminLogVos);

        return pageBean;
    }

    /**
     * @Description 调入审核日志
     * @author mzy
     * @time 2018-11-25
     * @see 
     * @return   edu.lsnu.equipment_management_system.pojo.domain.PageBean<edu.lsnu.equipment_management_system.pojo.vo.out.admin.AdminLogVo>
     * @params  [currentPage]
     */
    @Override
    public PageBean<AdminLogVo> transferInReviewLog(Integer currentPage) {
        // 获得总count：需要修改的位置
        Integer count = adminReviewLogMapperWithPaging.transferInReviewLogCount();
        // 构造pageBean
        PageBean<AdminLogVo> pageBean = new PageBean<>();
        // 重复的代码
        PageBeginAndPageSizeVo pageBeginAndPageSizeVo = repeatCode(count, currentPage, pageBean);
        // 需要修改的位置
        List<AdminLogVo> adminLogVos =
                adminReviewLogMapperWithPaging.transferInReviewLog(pageBeginAndPageSizeVo);

        pageBean.setContent(adminLogVos);

        return pageBean;
    }

    /**
     * @Description 调出审核日志
     * @author mzy
     * @time 2018-11-25
     * @see 
     * @return   edu.lsnu.equipment_management_system.pojo.domain.PageBean<edu.lsnu.equipment_management_system.pojo.vo.out.admin.AdminLogVo>
     * @params  [currentPage]
     */
    @Override
    public PageBean<AdminLogVo> transferOutReviewLog(Integer currentPage) {
        // 获得总count：需要修改的位置
        Integer count = adminReviewLogMapperWithPaging.transferOutReviewLogCount();
        // 构造pageBean
        PageBean<AdminLogVo> pageBean = new PageBean<>();
        // 重复的代码
        PageBeginAndPageSizeVo pageBeginAndPageSizeVo = repeatCode(count, currentPage, pageBean);
        // 需要修改的位置
        List<AdminLogVo> adminLogVos =
                adminReviewLogMapperWithPaging.transferOutReviewLog(pageBeginAndPageSizeVo);

        pageBean.setContent(adminLogVos);

        return pageBean;
    }

    /**
     * @Description 运行使用审核日志
     * @author mzy
     * @time 2018-11-26
     * @see
     * @return   edu.lsnu.equipment_management_system.pojo.domain.PageBean<edu.lsnu.equipment_management_system.pojo.vo.out.admin.AdminLogVo>
     * @params  [currentPage]
     */
    @Override
    public PageBean<AdminLogVo> useRecordReviewLog(Integer currentPage) {
        // 获得总count：需要修改的位置
        Integer count = adminReviewLogMapperWithPaging.useRecordReviewLogCount();
        // 构造pageBean
        PageBean<AdminLogVo> pageBean = new PageBean<>();
        // 重复的代码
        PageBeginAndPageSizeVo pageBeginAndPageSizeVo = repeatCode(count, currentPage, pageBean);
        // 需要修改的位置
        List<AdminLogVo> adminLogVos =
                adminReviewLogMapperWithPaging.useRecordReviewLog(pageBeginAndPageSizeVo);

        pageBean.setContent(adminLogVos);

        return pageBean;
    }

    /**
     * @Description 重复的分页代码，提取
     * @author mzy
     * @time 2018-11-25
     * @see
     * @return   edu.lsnu.equipment_management_system.pojo.vo.sql_conditions.PageBeginAndPageSizeVo
     * @params  [count, currentPage, pageBean]
     */
    private PageBeginAndPageSizeVo repeatCode(Integer count, Integer currentPage, PageBean<AdminLogVo> pageBean) {
        pageBean = (PageBean<AdminLogVo>) PageBeanDeal.getPageBean(count, currentPage, this.size, pageBean);

        // 查询当前页的List。
        PageBeginAndPageSizeVo pageBeginAndPageSizeVo = new PageBeginAndPageSizeVo();
        // 当前页开始的条数：(当前页 - 1) * 页容量
        Integer pageBegin = (pageBean.getCurrentPage() - 1)*pageBean.getPageSize();
        pageBeginAndPageSizeVo.setPageBegin(pageBegin);
        pageBeginAndPageSizeVo.setPageSize(pageBean.getPageSize());

        return pageBeginAndPageSizeVo;
    }
}
